<!--就业信息管理-->
<template>
  <div class="exam">
<!--    搜索栏-->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="formInline.name" placeholder="请输入姓名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="getCareerInfo">重置</el-button>
      </el-form-item>
    </el-form>
<!--    表格-->
    <el-table
      :data="form"
      style="width: 100%"
      border>
      <el-table-column
        label="学生姓名"
        width="180">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.Name }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="联系方式">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.PhoneNumber }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="就职单位">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.Employer }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="职位名称">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.Position}}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="就业状态">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.Status }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="待业原因">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.UnemployReason }}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="edit"
        label="编辑">

        <template v-slot="scope">
          <!--        编辑对话框-->
          <el-button type="primary" icon="el-icon-edit" @click="openEditDialog(scope.$index)"></el-button>
          <el-dialog title="编辑信息" :visible.sync="dialogVisibles[scope.$index]">

            <el-form v-model="editForm">
              <el-form-item label="就业状态" :label-width="formLabelWidth">
                <el-select v-model="editForm.Status">
                  <el-option label="已就业" value="1"></el-option>
                  <el-option label="未就业" value="0"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="就职单位" :label-width="formLabelWidth">
                <el-input v-model="editForm.Employer" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="职位名称" :label-width="formLabelWidth">
                <el-input v-model="editForm.Position" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="联系方式" :label-width="formLabelWidth">
                <el-input v-model="editForm.PhoneNumber" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="待业原因" :label-width="formLabelWidth">
                <el-input v-model="editForm.UnemployReason" autocomplete="off"></el-input>
              </el-form-item>
            </el-form>

            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogVisibles[scope.$index] = false">取 消</el-button>
              <el-button type="primary" @click="Edit(scope.$index,scope.row)">确 定</el-button>
            </div>
          </el-dialog>

          <!--        删除对话框-->
          <el-button type="primary" icon="el-icon-delete" @click="openDeleteDialog(scope.$index)"></el-button>
          <el-dialog
            title="提示"
            :visible.sync="DeleteDialogVisibles[scope.$index]"
            width="30%">
            <span>确定删除信息？</span>
            <span slot="footer" class="dialog-footer">
            <el-button @click="DeleteDialogVisibles[scope.$index] = false">取 消</el-button>
            <el-button type="primary" @click="Delete(scope.$index,scope.row)">确 定</el-button>
          </span>
          </el-dialog>
        </template>

      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagination.current"
      :page-sizes="[6, 10]"
      :page-size="pagination.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pagination.total"
      class="page"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  name: "careerInfo",
  data() {
    return {
      form: [], //保存后端获取就业信息
      editForm:{
        StudentID: "",
        Status:null,
        Employer:"",
        Position:"",
        PhoneNumber:"",
        UnemployReason:''
      },
      pagination: { //分页后的考试信息
        current: 1, //当前页
        total: null, //记录条数
        size: 5 //每页条数
      },
      formInline: {
        name: '',
        region: ''
      },
      formLabelWidth:'90px',
      dialogVisibles:{},
      DeleteDialogVisibles:{}
    }
  },
  created() {
    this.getCareerInfo()
  },
  methods: {
    getCareerInfo() { //分页查询所有试卷信息
      this.$axios({
        url:'/api/teacher/careerList',
        method:'get',
        params:{
          page:this.pagination.current,
          size:this.pagination.size
        },
        headers:{
          "Authorization":this.$cookies.get('token')
      }
      }).then(res =>{
        this.pagination=res.data.data
        this.form = res.data.data.records
        console.log(this.form)
      })
    },
    //改变当前记录条数
    handleSizeChange(val) {
      this.pagination.size = val
      this.getCareerInfo()
    },
    //改变当前页码，重新发送请求
    handleCurrentChange(val) {
      this.pagination.current = val
      this.getCareerInfo()
    },
    //修改
    Edit(index,row){
      // this.editDialog = false
      this.editForm.StudentID = this.form[index].StudentID
      this.dialogVisibles[this.form.indexOf(row)] = false
      console.log(index)
      this.$axios({
        url:'/api/track/editTrack',
        method:'post',
        data:this.editForm,
        headers:{
          'Authorization':this.$cookies.get('token')
        }
      }).then(res =>{
        if(res.data.code === 0){
          this.$message.success("修改成功")
          this.getCareerInfo()
        }else {
          this.$message.error("修改失败")
        }
      })
    },
    //删除
    Delete(index,row){
      this.DeleteDialogVisibles[this.form.indexOf(row)] = false
      this.$axios({
        url:'/api/track/deleteTrack',
        method:'delete',
        params:{
          id:this.form[index].StudentID
        },
        headers:{
          'Authorization':this.$cookies.get('token')
        }
      }).then(res =>{
        if(res.data.code === 0){
          this.$message.success("删除成功")
          this.getCareerInfo()
        }else {
          this.$message.error("删除失败")
        }
      })
    },
    //查找
    onSubmit(){
      this.$axios({
        url:'/api/track/findByName',
        method:'get',
        params:{
          name:this.formInline.name
        },
        headers:{
          'Authorization':this.$cookies.get('token')
        }
      }).then(res =>{
        this.pagination = res.data.data
        this.form = res.data.data.records
        if(res.data.code !== 0){
          this.$message.error(res.data.message)
        }
      })
    },

    openEditDialog(index){
      this.$set(this.dialogVisibles,index,true)
    },
    openDeleteDialog(index){
      this.$set(this.DeleteDialogVisibles,index,true)
    }
  },
}
</script>

<style lang="less" scoped>
.exam {
  padding: 0px 40px;
  .page {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .edit{
    margin-left: 20px;
  }
}
</style>
